package com.wxy.ideaplugin.ui;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.sun.istack.Nullable;
import com.wxy.ideaplugin.generator.MenuService;
import com.wxy.ideaplugin.generator.MpGeneratorThread;
import com.wxy.ideaplugin.utils.*;
import okhttp3.Response;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.*;
import java.util.List;

@Service
public class AiCodeUi {
    private static final Logger log = LoggerFactory.getLogger(AiCodeUi.class);
    private JPanel myJpanel;
    private JButton genMenu;
    private JTabbedPane tabbedPane1;
    //private JEditorPane editorPane_menu;
    private JTextField textField_systemName;
    private JEditorPane editorPane_input;
    private JButton sendButton;
    private JButton sqlGenButton;
    private JTextArea aiLog_textArea;
    private JButton sqlExcuteButton;
    private JButton genCodeButton;
    private JTextField textField_prefix;
    private JTextArea menu_textArea;
    private JTextArea aichat_textArea;
    private JTextArea execlog_textArea;
    private JTextArea log_textArea_m2;
    private JTextField tableName_textField_m2;
    private JButton genCode_Btn_m2;
    private JButton genMenu_Btn_m2;
    private JTextField tablePrefix_textField_m2;
    private JScrollPane log_jscrollPane_m2;
    private Map<String, String> resourceMap;
    // table name
    private List<Map<String, String>> tableInfoList = new ArrayList<>();
    //
    public static String projectPath;

    public AiCodeUi(String projectPath) {
        //test
        textField_systemName.setText("OA办公系统");
        textField_prefix.setText("toa_");
        tableName_textField_m2.setText("tai_chatai,tai_chatai_test");
        tablePrefix_textField_m2.setText("tai_");
        //
        AiCodeUi.projectPath = projectPath;
        //S1:发送AI：生成系统功能结构
        sendButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String softwareName = textField_systemName.getText();
                String tablePrefix = textField_prefix.getText();
                //优化问题
                String msg =
                        "你是一位数据库设计师，设计一款软件系统，系统名称叫##softwareName##，请编写出系统的数据库表名的JSON结构，对数据库表名进行分类分组，JSON结构格式是，json键：功能组名称，json值：表名列表结构，" +
                                "表名结尾去掉'表'字；json脚本内容，不要省略，需要显示全部数据；json结构中只显示功能组名称和数据表名称，不要显示系统名称；组名和表名使用中文描述；脚本开头用```json。";
                msg = msg.replaceAll("##softwareName##", softwareName);
                editorPane_input.setText(msg);

                String q = editorPane_input.getText();
                menu_textArea.setText("#AI思考中...");

                //查询缓存
                //String querySql = "select * from tai_chatai where q = ? and (resp is not null and resp!='')";
                String querySql = "select * from tai_chatai where domain_name = ? and (resp is not null and resp!='')";
                List paramList = new ArrayList();
                //paramList.add(q);
                paramList.add(softwareName + "###SystemMenuGroup");
                List<Map<String, Object>> list = JdbcUtils.executeQuery(querySql, paramList);
                if (!list.isEmpty()) {
                    menu_textArea.setText("");
                    Map<String, Object> map = list.get(list.size() - 1);
                    String result = (String) map.get("resp");
                    result = HttpUtils.parseGroupMenuList(result);
                    menu_textArea.setText(result);
                    return;
                }
                //chat api
                HttpUtils.getInstance().chatApiV2(q, new EventSourceListener() {
                    StringBuilder resultSb = new StringBuilder();

                    @Override
                    public void onOpen(EventSource eventSource, Response response) {
                        log.info("----onOpen");
                        menu_textArea.setText("");
                        super.onOpen(eventSource, response);
                    }

                    @Override
                    public void onEvent(EventSource eventSource, @Nullable String id, @Nullable String type, String data) {
                        log.info("----onEvent");
                        JSONObject dataJo = JSONObject.parseObject(data);
                        boolean is_end = dataJo.getBoolean("is_end");
                        String result = dataJo.getString("result");
                        menu_textArea.append(result);
                        resultSb.append(result);
                        if (is_end == true) {
                            log.info(resultSb.toString());
                            // 查询出的结果，进行缓存
                            String insertSql = "insert into tai_chatai(id, domain_name, q, table_prefix, resp) values(?,?,?,?,?)";
                            List paramList = new ArrayList();
                            paramList.add(IdUtils.genId());
                            paramList.add(softwareName + "###SystemMenuGroup");
                            paramList.add(q);
                            paramList.add(tablePrefix);
                            paramList.add(resultSb.toString());
                            JdbcUtils.executeInsert(insertSql, paramList);
                            //parse data
                            String result2 = HttpUtils.parseGroupMenuList(resultSb.toString());
                            menu_textArea.setText(result2);
                        }
                        super.onEvent(eventSource, id, type, data);
                    }

                    @Override
                    public void onClosed(EventSource eventSource) {
                        log.info("----onClosed");
                        super.onClosed(eventSource);
                    }

                    @Override
                    public void onFailure(EventSource eventSource, @Nullable Throwable t, @Nullable Response response) {
                        log.info("----onFailure");
                        try {
                            log.info(response.body().string());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        super.onFailure(eventSource, t, response);
                    }
                });
            }
        });
        //S2:生成模型脚本
        sqlGenButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String softwareName = textField_systemName.getText();
                String tablePrefix = textField_prefix.getText();
                String groupMenuJsonStr = menu_textArea.getText();
                JSONObject groupMenuJson = JSONObject.parseObject(groupMenuJsonStr);
                SqlGenThread sqlGenThread = new SqlGenThread(groupMenuJson, softwareName, tablePrefix, aiLog_textArea, aichat_textArea, tableInfoList);
                sqlGenThread.start();
                // ai resource file
                if (projectPath != null) {
                    resourceMap = AiResourceUtils.parseAiCodeResourceFile(projectPath);
                    resourceMap.put("softwareName", softwareName);
                    resourceMap.put("tablePrefix", tablePrefix);
                    if (!resourceMap.containsKey("outputDirMain")) {
                        resourceMap.put("outputDirMain", projectPath);
                    }
                    if (!resourceMap.containsKey("javaDir")) {
                        resourceMap.put("javaDir", "/src/main/java");
                    }
                    // tables
                    if (!tableInfoList.isEmpty()) {
                        //分组
                        //tableName 与 tableNameZh 映射
                        Map<String, String> tableNameZh_tableNameMap = new HashMap<>();
                        for (Map<String, String> tableInfoMap : tableInfoList) {
                            String tableName = tableInfoMap.get("tableName");
                            String tableNameZh = tableInfoMap.get("tableNameZh");
                            tableNameZh_tableNameMap.put(tableNameZh, tableName);
                        }
                        resourceMap.put("groupMenuJsonStr", groupMenuJsonStr);
                    }
                }
            }
        });
        //S3-1,执行模型脚本
        sqlExcuteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SqlExecThread sqlExecThread = new SqlExecThread(aiLog_textArea, execlog_textArea);
                sqlExecThread.start();
            }
        });
        //S3-2,生成源码
        genCodeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String softwareName = textField_systemName.getText();
                String tablePrefix = textField_prefix.getText();
                // ai resource file
                resourceMap = AiResourceUtils.parseAiCodeResourceFile(projectPath);
                resourceMap.put("softwareName", softwareName);
                resourceMap.put("tablePrefix", tablePrefix);
                if (!resourceMap.containsKey("outputDirMain")) {
                    resourceMap.put("outputDirMain", projectPath);
                }
                if (!resourceMap.containsKey("javaDir")) {
                    resourceMap.put("javaDir", "/src/main/java");
                }
                // tables
                if (!tableInfoList.isEmpty()) {
                    //分组
                    //tableName 与 tableNameZh 映射
                    Map<String, String> tableNameZh_tableNameMap = new HashMap<>();
                    for (Map<String, String> tableInfoMap : tableInfoList) {
                        String tableName = tableInfoMap.get("tableName");
                        String tableNameZh = tableInfoMap.get("tableNameZh");
                        tableNameZh_tableNameMap.put(tableNameZh, tableName);
                    }
                    String groupMenuJsonStr = menu_textArea.getText();
                    resourceMap.put("groupMenuJsonStr", groupMenuJsonStr);
                    Map<String, String> resourceMap4Code = new HashMap<>();
                    resourceMap4Code.putAll(resourceMap);
                    MpGeneratorThread mpGeneratorThread = new MpGeneratorThread(resourceMap4Code, execlog_textArea, tableNameZh_tableNameMap, projectPath);
                    mpGeneratorThread.start();
                }
            }
        });
        //S3-3,生成菜单
        genMenu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //滚动尾部
                JScrollPane scrollPane1 = (JScrollPane) aiLog_textArea.getParent().getParent();
                JScrollBar scrollBar = scrollPane1.getVerticalScrollBar();
                //
                String softwareName = textField_systemName.getText();
                String tablePrefix = textField_prefix.getText();
                String contextPath = resourceMap.get("contextPath");
                String module = resourceMap.get("module");
                String groupMenuJsonStr = menu_textArea.getText();
                JSONObject groupMenuJson = JSONObject.parseObject(groupMenuJsonStr);
                //
                Map<String, String> tableNameZh_domainMap = getTableNameZh_domainMap(tableInfoList, tablePrefix, groupMenuJsonStr);
                //add menu
                MenuService menuService = new MenuService(softwareName, groupMenuJson, tableInfoList, tablePrefix, contextPath, module, tableNameZh_domainMap, execlog_textArea);
                menuService.start();
                //滚动尾部
                scrollBar.setValue(scrollBar.getMaximum());
            }
        });
        //逆向代码模式:生成源码
        genCode_Btn_m2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String tablePrefix = tablePrefix_textField_m2.getText();
                //
                Map<String, Object> tableMap = genGroupMenuJsonStr_m2();
                String groupMenuJsonStr = (String) tableMap.get("groupMenuJsonStr");
                List<Map<String, String>> tableInfoList = (List<Map<String, String>>) tableMap.get("tableInfoList");

                // ai resource file
                resourceMap = AiResourceUtils.parseAiCodeResourceFile(projectPath);
                resourceMap.put("softwareName", "");
                resourceMap.put("tablePrefix", tablePrefix);
                if (!resourceMap.containsKey("outputDirMain")) {
                    resourceMap.put("outputDirMain", projectPath);
                }
                if (!resourceMap.containsKey("javaDir")) {
                    resourceMap.put("javaDir", "/src/main/java");
                }
                // tables
                if (!tableInfoList.isEmpty()) {
                    //分组
                    //tableName 与 tableNameZh 映射
                    Map<String, String> tableNameZh_tableNameMap = new HashMap<>();
                    for (Map<String, String> tableInfoMap : tableInfoList) {
                        String tableName = tableInfoMap.get("tableName");
                        String tableNameZh = tableInfoMap.get("tableNameZh");
                        tableNameZh_tableNameMap.put(tableNameZh, tableName);
                    }
                    resourceMap.put("groupMenuJsonStr", groupMenuJsonStr);
                    Map<String, String> resourceMap4Code = new HashMap<>();
                    resourceMap4Code.putAll(resourceMap);
                    MpGeneratorThread mpGeneratorThread = new MpGeneratorThread(resourceMap4Code, log_textArea_m2, tableNameZh_tableNameMap, projectPath);
                    mpGeneratorThread.start();
                }
            }
        });
        //逆向代码模式:生成菜单
        genMenu_Btn_m2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //滚动尾部
                JScrollBar scrollBar = log_jscrollPane_m2.getVerticalScrollBar();
                //
                Map<String, Object> tableMap = genGroupMenuJsonStr_m2();
                String groupMenuJsonStr = (String) tableMap.get("groupMenuJsonStr");
                List<Map<String, String>> tableInfoList = (List<Map<String, String>>) tableMap.get("tableInfoList");
                //
                String softwareName = "临时菜单";
                String tablePrefix = tablePrefix_textField_m2.getText();
                String contextPath = resourceMap.get("contextPath");
                String module = resourceMap.get("module");
                JSONObject groupMenuJson = JSONObject.parseObject(groupMenuJsonStr);
                //
                Map<String, String> tableNameZh_domainMap = getTableNameZh_domainMap(tableInfoList, tablePrefix, groupMenuJsonStr);
                //add menu
                MenuService menuService = new MenuService(softwareName, groupMenuJson, tableInfoList, tablePrefix, contextPath, module, tableNameZh_domainMap, log_textArea_m2);
                menuService.start();
                //滚动尾部
                scrollBar.setValue(scrollBar.getMaximum());
            }
        });
    }

    private Map<String, Object> genGroupMenuJsonStr_m2() {
        //tableNameList
        List<String> tableNameList = null;
        String tableName_text = tableName_textField_m2.getText();
        if (tableName_text.contains(",")) {
            tableNameList = Arrays.asList(tableName_text.split(","));
        } else {
            tableNameList = new ArrayList<>();
            tableNameList.add(tableName_text);
        }
        //
        JSONArray ja1 = new JSONArray();
        List<Map<String, String>> tableInfoList = new ArrayList<>();
        for (String tableNameTmp : tableNameList) {
            Map<String, String> tableInfoMap = new HashMap<>();
            tableInfoMap.put("tableName", tableNameTmp);
            tableInfoMap.put("tableNameZh", tableNameTmp);
            tableInfoList.add(tableInfoMap);
            ja1.add(tableNameTmp);
        }
        //{"tableNameTmp":["tableNameTmp"]}
        JSONObject jo = new JSONObject();
        jo.put("临时组", ja1);
        String groupMenuJsonStr = jo.toJSONString();
        //
        Map<String, Object> map = new HashMap<>();
        map.put("groupMenuJsonStr", groupMenuJsonStr);
        map.put("tableInfoList", tableInfoList);
        return map;
    }

    private Map<String, String> getTableNameZh_domainMap(List<Map<String, String>> tableInfoList, String tablePrefix, String groupMenuJsonStr) {
        //tableName 与 tableNameZh 映射
        Map<String, String> tableNameZh_tableNameMap = new HashMap<>();
        for (Map<String, String> tableInfoMap : tableInfoList) {
            String tableName = tableInfoMap.get("tableName");
            String tableNameZh = tableInfoMap.get("tableNameZh");
            tableNameZh_tableNameMap.put(tableNameZh, tableName);
        }
        //
        Map<String, String> tableNameZh_domainMap = new HashMap<>();
        JSONObject groupMenuJson = JSONObject.parseObject(groupMenuJsonStr);
        for (String groupName : groupMenuJson.keySet()) {
            //二级菜单 如：key = 用户管理
            String domain = "";
            JSONArray tableNameZhList = groupMenuJson.getJSONArray(groupName); //["用户", "用户地址", "用户购物车", "用户订单"]
            for (int i = 0; i < tableNameZhList.size(); i++) {
                String tableNameZh = (String) tableNameZhList.get(i);
                String tableName = tableNameZh_tableNameMap.get(tableNameZh);
                String tableName_noPrefix = "";
                if (tableName.startsWith(tablePrefix)) {
                    tableName_noPrefix = tableName.replaceFirst(tablePrefix, "");
                }
                //第一个表名,前部分作为domain
                if (i == 0) {
                    if (tableName_noPrefix.contains("_")) {
                        String t1 = tableName_noPrefix.substring(0, tableName_noPrefix.lastIndexOf("_"));
                        String domainProperty = SwitchLineCamel.switch2Property(t1);
                        domain = domainProperty.substring(0, 1).toLowerCase() + domainProperty.substring(1);
                    } else {
                        String domainProperty = SwitchLineCamel.switch2Property(tableName_noPrefix);
                        domain = domainProperty.substring(0, 1).toLowerCase() + domainProperty.substring(1);
                    }
                }
                tableNameZh_domainMap.put(tableNameZh, domain);
            }
        }
        return tableNameZh_domainMap;
    }

    public static void main(String[] args) {
        /*Map<String, String> resourceMap = new HashMap<>();
        resourceMap.put("jdbcDriver", "com.mysql.cj.jdbc.Driver");
        resourceMap.put("jdbcUrl", "jdbc:mysql://127.0.0.1:3309/db_lowcode?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&pinGlobalTxToPhysicalConnection=true&useSSL=false");
        resourceMap.put("username", "root");
        resourceMap.put("password", "123456");
        resourceMap.put("outputVueDirProj", "/Users/wxy2020/workspace/gitee/lowcode-ui"); // vue proj path
        resourceMap.put("outputDirProj", "/Users/wxy2020/workspace/gitee/lowcode2/flow");
        resourceMap.put("javaDir", "/src/main/java");
        resourceMap.put("packagePath", "/com/wxy/ej/flow/modules");
        resourceMap.put("contextPath", "flow");
        resourceMap.put("module", "shop");
        resourceMap.put("domain", "order");
        resourceMap.put("tables", "tttt_product_category,tttt_test_employer");
        resourceMap.put("tablePrefix", "tttt_");*/
        AiCodeUi aiCodeUi = new AiCodeUi("/Users/wxy2020/workspace/gitee/lowcode2/");
        aiCodeUi.initUi();


    }


    public void initUi() {
        JFrame frame = new JFrame("AiCodeUi");
        frame.setContentPane(myJpanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setSize(1200, 1000);
        frame.setLocationRelativeTo(myJpanel);
        //myJpanel.setSize(1200, 1000);
        //tabbedPane1.setSize(1200, 1000);
        //textPane_input.setSize(new Dimension(300, 200));
        frame.setVisible(true);
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        myJpanel = new JPanel();
        myJpanel.setLayout(new FormLayout("fill:876px:grow", "center:927px:noGrow"));
        tabbedPane1 = new JTabbedPane();
        tabbedPane1.setToolTipText("生成框架>生成建表脚本>生成源码>生成菜单 ");
        CellConstraints cc = new CellConstraints();
        myJpanel.add(tabbedPane1, cc.xy(1, 1, CellConstraints.DEFAULT, CellConstraints.FILL));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new FormLayout("center:782px:grow,left:4dlu:noGrow,fill:d:grow", "center:max(d;4px):noGrow,top:3dlu:noGrow,center:max(d;4px):noGrow,top:3dlu:noGrow,center:max(d;4px):noGrow,top:3dlu:noGrow,center:max(d;4px):noGrow,top:3dlu:noGrow,center:d:grow"));
        tabbedPane1.addTab("AI生成系统模式： 步骤1", panel1);
        final JLabel label1 = new JLabel();
        label1.setText("优化输入问题");
        panel1.add(label1, cc.xyw(1, 3, 3));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayoutManager(1, 5, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel2, cc.xyw(1, 1, 3, CellConstraints.FILL, CellConstraints.FILL));
        panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        final JLabel label2 = new JLabel();
        label2.setText("需要生成的系统名称");
        panel2.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(63, 33), null, 0, false));
        textField_systemName = new JTextField();
        textField_systemName.setText("");
        panel2.add(textField_systemName, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(300, -1), new Dimension(300, 33), new Dimension(400, -1), 0, false));
        sendButton = new JButton();
        sendButton.setText("发送");
        panel2.add(sendButton, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label3 = new JLabel();
        label3.setText("系统对应的表名前缀");
        panel2.add(label3, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        textField_prefix = new JTextField();
        panel2.add(textField_prefix, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JScrollPane scrollPane1 = new JScrollPane();
        panel1.add(scrollPane1, cc.xyw(1, 9, 3, CellConstraints.FILL, CellConstraints.FILL));
        menu_textArea = new JTextArea();
        scrollPane1.setViewportView(menu_textArea);
        final JLabel label4 = new JLabel();
        label4.setText("AI响应数据库表分类结构（可增删成符合自己要求的内容）");
        panel1.add(label4, cc.xy(1, 7));
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel3, cc.xyw(1, 5, 3, CellConstraints.FILL, CellConstraints.FILL));
        panel3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
        editorPane_input = new JEditorPane();
        panel3.add(editorPane_input, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel4 = new JPanel();
        panel4.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
        tabbedPane1.addTab("步骤2", panel4);
        final JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        panel4.add(panel5, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        sqlGenButton = new JButton();
        sqlGenButton.setText("生成模型脚本");
        panel5.add(sqlGenButton);
        final JScrollPane scrollPane2 = new JScrollPane();
        panel4.add(scrollPane2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        aichat_textArea = new JTextArea();
        aichat_textArea.setLineWrap(true);
        aichat_textArea.setRows(8);
        aichat_textArea.setText("AI处理过程日志框");
        aichat_textArea.setToolTipText("AI处理过程日志框");
        scrollPane2.setViewportView(aichat_textArea);
        final JScrollPane scrollPane3 = new JScrollPane();
        panel4.add(scrollPane3, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        aiLog_textArea = new JTextArea();
        aiLog_textArea.setColumns(0);
        aiLog_textArea.setEditable(true);
        aiLog_textArea.setEnabled(true);
        aiLog_textArea.setLineWrap(true);
        aiLog_textArea.setRows(0);
        aiLog_textArea.setText("系统分析日志框");
        aiLog_textArea.setToolTipText("系统分析日志框");
        scrollPane3.setViewportView(aiLog_textArea);
        final JPanel panel6 = new JPanel();
        panel6.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
        tabbedPane1.addTab("步骤3", panel6);
        final JPanel panel7 = new JPanel();
        panel7.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        panel6.add(panel7, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        sqlExcuteButton = new JButton();
        sqlExcuteButton.setText("1,执行模型脚本");
        panel7.add(sqlExcuteButton);
        genCodeButton = new JButton();
        genCodeButton.setText("2,生成源码");
        panel7.add(genCodeButton);
        genMenu = new JButton();
        genMenu.setText("3,生成菜单");
        panel7.add(genMenu);
        final JScrollPane scrollPane4 = new JScrollPane();
        panel6.add(scrollPane4, new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        execlog_textArea = new JTextArea();
        execlog_textArea.setText("");
        scrollPane4.setViewportView(execlog_textArea);
        final JPanel panel8 = new JPanel();
        panel8.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        tabbedPane1.addTab("逆向生成模式：现有表>生成源码>生成菜单", panel8);
        final JPanel panel9 = new JPanel();
        panel9.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel8.add(panel9, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel10 = new JPanel();
        panel10.setLayout(new GridLayoutManager(1, 8, new Insets(0, 0, 0, 0), -1, -1));
        panel9.add(panel10, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final Spacer spacer1 = new Spacer();
        panel10.add(spacer1, new GridConstraints(0, 6, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        genCode_Btn_m2 = new JButton();
        genCode_Btn_m2.setText("生成源码");
        panel10.add(genCode_Btn_m2, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        genMenu_Btn_m2 = new JButton();
        genMenu_Btn_m2.setText("生成菜单");
        panel10.add(genMenu_Btn_m2, new GridConstraints(0, 7, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        tableName_textField_m2 = new JTextField();
        tableName_textField_m2.setText("");
        panel10.add(tableName_textField_m2, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        final JLabel label5 = new JLabel();
        label5.setText("表名");
        panel10.add(label5, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label6 = new JLabel();
        label6.setText("表前缀");
        panel10.add(label6, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        tablePrefix_textField_m2 = new JTextField();
        tablePrefix_textField_m2.setText("");
        panel10.add(tablePrefix_textField_m2, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        log_jscrollPane_m2 = new JScrollPane();
        panel8.add(log_jscrollPane_m2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        log_textArea_m2 = new JTextArea();
        log_jscrollPane_m2.setViewportView(log_textArea_m2);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return myJpanel;
    }

}
